package main

func main() {

}

func subarraySum(nums []int, k int) int {
	preMap := make(map[int]int, len(nums))
	count := 0
	pre := 0
	for i := 0; i < len(nums); i++ {
		pre = pre + nums[i]
		if _, ok := preMap[pre-k]; ok {
			count += preMap[pre-k]
		}
		preMap[pre]++
	}
	return count
}
